<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login - manage - www.adpython.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>

<link rel="shortcut icon" href="/images/favicon.ico" />
<link href="/css/manage.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/ajax.js"></script>
<script type="text/javascript">
function register(){
	var username=document.getElementById('loginname').value;
	if(username==''){
		alert("Your username is empty, please input a valid email address.");
		return false;
	}
	if(!(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.exec(username))){
		alert("Your username is not a valid email address.");
		return false;
	}
	var password=document.getElementById('password').value;
	var re_password=document.getElementById('re_password').value;
	if(password.length<8){
		alert("Password must be minimum of 8 characters in length.");
		return false;
	}
	if(password!=re_password){
		alert("Your repeat password is not equal to the password.");
		return false;
	}
	document.getElementById('f').submit();
}

function checkUsername(){
	var request=createRequest();
	if(request){
		var loginname=document.getElementById('loginname').value;
		if(loginname!=''){
			var url="/login.htm?method=checkUsername&loginname="+loginname;
			request.open("GET", url, true);
			request.onreadystatechange = function(){
				if(request.readyState==4&&request.status==200){
					var result=request.responseText;
					var json = eval("(" + result + ")");
					if(json.exists=='true'){
						alert('该用户名已经被注册了，请您选择其他用户名.');
						document.getElementById('loginname').value='';
						document.getElementById('password').value='';
						document.getElementById('re_password').value='';
					}
				}
			};
			request.send(null);
		}
	}
}
</script>
</head>
<body>
	<%@ include file="header.jsp" %>
	<div class="content">
		<div class="small_table">
			<form action="/login.htm?method=register" id="f" name="f" method="post">
				<div class="title">Register a new user</div>
				<table cellspacing="10px;">
					<tr><td><span class="left">UserName:</span></td><td><span class="right"><input class="txtinput" type="text" name="loginname" id="loginname" value="" onchange="checkUsername();" /></span><p class="explan">Should be a valid email address.</p></td></tr>
					<tr><td><span class="left">Password:</span></td><td><span class="right"><input class="txtinput" type="password" name="password" id="password" value=""/></span><p class="explan">Minimum of 8 characters in length.</p></td></tr>
					<tr><td><span class="left">Repeat password:</span></td><td><span class="right"><input class="txtinput" type="password" name="re_password" id="re_password" value=""/></span></td></tr>
					<tr><td><span class="left"><input class="btn" type="button" value="Register" onclick="register();"/></span></td><td></td></tr>
					<tr><td colspan="2"><span class="other_info">[ <a href="/login.htm?method=login">I already have an account</a> ]</span></td></tr>
				</table>
			</form>
		</div>
	</div>
	<%@ include file="footer.jsp" %>
</body>
</html>